#include <os/mm.h>

ptr_t memCurr = FREEMEM;
int free_page_num = 0;
ptr_t management[100];

ptr_t allocPage()
{
    // align PAGE_SIZE
    ptr_t ret;
    if(free_page_num){
        free_page_num--;
        ret = management[free_page_num];
    }
    else{
        ret = ROUND(memCurr, PAGE_SIZE);
        memCurr = ret + PAGE_SIZE;
        ret = ret + PAGE_SIZE;
    }
    return ret;
}

void* kmalloc(size_t size)
{
    ptr_t ret = ROUND(memCurr, 4);
    memCurr = ret + size;
    return (void*)ret;
}

void freePage(ptr_t baseaddr)
{
	ptr_t addr = ROUND(baseaddr, PAGE_SIZE);
    management[free_page_num++] = addr;
}